/***************************************************************************************************
 *Copyright(C),2010-2016,Sumscope
 *FileName	:  allocator_pool_manager.cpp
 *Author	:  scofined.qi
 *Version	:  1.0
 *Date		:  2019/01/14
 *Desc		:  //用于主要说明此程序文件完成的主要功能
 *Relation :
 *Others	:  //其他内容说明
 *Function :  //主要函数列表，每条记录应包含函数名及功能简要说明
 *History	:
 * //修改历史记录列表，每条修改记录应包含修改日期、修改者及修改内容简介
 ***************************************************************************************************/
#include "allocator_pool_manager.h"

#include "allocator_pool.h"

namespace qb {
namespace base {
AllocatorInterface::AllocatorInterface(int itemSize)
    : m_item_size(itemSize), m_allocator(new HeapAllocator("AllocatorPool")) {}
AllocatorInterface::~AllocatorInterface() {
  if (m_allocator) delete m_allocator;
  m_allocator = nullptr;
}
void* AllocatorInterface::Alloc(int bytes) { return m_allocator->Alloc(bytes); }
void AllocatorInterface::Free(void* ptr, int bytes) {
  return m_allocator->Free(ptr, bytes);
}

void HeapAllocator::DumpAllHeaps() {}
HeapAllocator::HeapAllocator(const char* name) : m_name(name ? name : "") {}
HeapAllocator::~HeapAllocator() { Reset(); }

void HeapAllocator::Reset() { m_usedsize = 0; }

void* HeapAllocator::Alloc(int bytes) { return malloc(bytes); }

void HeapAllocator::Free(void* ptr, int bytes) {
  if (ptr) ::free(ptr);
  return;
}
int HeapAllocator::GetBytes() const { return m_usedsize; }
void HeapAllocator::DumpStatus() {}
}  // namespace base
}  // namespace qb